let rec power x n=
      if n<0 then
          invalid_arg "puissance negative"
      else
   
      match n with
          0 -> 1
         |_ -> x * power x (n-1);;


let rec application liste x =
      match liste with
     [] -> 0
    |(a,b)::l when a <= 0 -> failwith "le coefficient est negatif ou nul"
    |(a,0)::l -> a + application l x 
    |(a,b)::l -> a * power x b + application l x ;; 

application [(2,2);(2,3);(4,4)] 2;;

let rec add l1 l2=
      match (l1,l2) with
      ([],[]) -> []
     |([],(a,b)::l1) -> (a,b)::l1
     |((c,d)::l2,[]) -> (c,d)::l2
     |((a,b)::l1 , (c,d)::l2) when b=d -> (a+c,b):: add l1 l2
     |((a,b)::l1 , (c,d)::l2) when b<d -> (a,b)::(c,d)::add l1 l2                   
     |((a,b)::l1 , (c,d)::l2) when b>d -> (c,d)::(a,b)::add l1 l2                   
     |((a,b)::l1 , (c,d)::l2) -> [];;
                              
    
add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

let rec soustract l1 l2=
      match (l1,l2) with
      ([],[]) -> []
     |([],(a,b)::l1) -> (a,b)::l1
     |((c,d)::l2,[]) -> (c,d)::l2
     |((a,b)::l1 , (c,d)::l2) when b=d -> (a-c,b):: soustract l1 l2
     |((a,b)::l1 , (c,d)::l2) when b<d -> (a,b)::(-c,d)::soustract l1 l2                   
     |((a,b)::l1 , (c,d)::l2) when b>d -> (-c,d)::(a,b)::soustract l1 l2                   
     |((a,b)::l1 , (c,d)::l2) -> [];;

soustract  [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

let rec deriv liste=
      match liste with
      [] -> []
     |(a,b)::liste -> (b*a,b-1)::deriv liste;;

deriv [(2,2);(2,3);(4,4)];;

